import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number
  uid: number
  race: string
  affixes: string // 种族词条，逗号分隔
  level: number
  stage: string
  exp: number

  // 八项基础属性
  constitution_base: number
  spirit_base: number
  strength_base: number
  intelligence_base: number
  agility_base: number
  perception_base: number
  charm_base: number
  luck_base: number

  // 八项成长属性
  constitution_growth: number
  spirit_growth: number
  strength_growth: number
  intelligence_growth: number
  agility_growth: number
  perception_growth: number
  charm_growth: number
  luck_growth: number

  // 八项额外属性
  constitution_extra: number
  spirit_extra: number
  strength_extra: number
  intelligence_extra: number
  agility_extra: number
  perception_extra: number
  charm_extra: number
  luck_extra: number

  // 八项最终属性
  constitution_final: number
  spirit_final: number
  strength_final: number
  intelligence_final: number
  agility_final: number
  perception_final: number
  charm_final: number
  luck_final: number

  hp_max: number
  hp: number
  mp_max: number
  mp: number
  atk: number
  matk: number
  def: number
  mdef: number
  hit: number
  dodge: number
  crit: number
  crit_dmg: number
  crit_avoid: number
  crit_resist: number
  speed: number
  tenacity: number
  hp_recover: number
  mp_recover: number

  // 物理精通
  stab_mastery: number
  slash_mastery: number
  strike_mastery: number

  // 物理抗性
  stab_resist: number
  slash_resist: number
  strike_resist: number

  // 元素精通
  metal_mastery: number
  wood_mastery: number
  water_mastery: number
  fire_mastery: number
  earth_mastery: number
  ice_mastery: number
  thunder_mastery: number
  wind_mastery: number
  light_mastery: number
  dark_mastery: number

  // 元素抗性
  metal_resist: number
  wood_resist: number
  water_resist: number
  fire_resist: number
  earth_resist: number
  ice_resist: number
  thunder_resist: number
  wind_resist: number
  light_resist: number
  dark_resist: number
}

class user_attribute extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

user_attribute.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '自增主键'
    },
    uid: {
      type: DataTypes.BIGINT,
      allowNull: false,
      unique: true,
      comment: '用户uid'
    },
    race: {
      type: DataTypes.STRING(50),
      allowNull: false,
      defaultValue: '',
      comment: '种族'
    },
    affixes: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: '',
      comment: '种族词条，逗号分隔'
    },
    level: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '等级'
    },
    stage: {
      type: DataTypes.STRING(50),
      allowNull: false,
      defaultValue: '',
      comment: '等阶'
    },
    exp: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: 0,
      comment: '经验'
    },
    // 八项基础属性
    constitution_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '体质'
    },
    spirit_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '精神'
    },
    strength_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '力量'
    },
    intelligence_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '智力'
    },
    agility_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '敏捷'
    },
    perception_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '感知'
    },
    charm_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '魅力'
    },
    luck_base: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '幸运'
    },
    // 八项额外属性
    constitution_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '体质'
    },
    spirit_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '精神'
    },
    strength_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '力量'
    },
    intelligence_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '智力'
    },
    agility_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '敏捷'
    },
    perception_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '感知'
    },
    charm_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '魅力'
    },
    luck_extra: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '幸运'
    },
    // 八项成长属性
    constitution_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '体质成长'
    },
    spirit_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '精神成长'
    },
    strength_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '力量成长'
    },
    intelligence_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '智力成长'
    },
    agility_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '敏捷成长'
    },
    perception_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '感知成长'
    },
    charm_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '魅力成长'
    },
    luck_growth: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '幸运成长'
    },
    // 八项最终属性
    constitution_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '体质最终'
    },
    spirit_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '精神最终'
    },
    strength_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '力量最终'
    },
    intelligence_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '智力最终'
    },
    agility_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '敏捷最终'
    },
    perception_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '感知最终'
    },
    charm_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '魅力最终'
    },
    luck_final: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '幸运最终'
    },
    hp_max: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '生命上限'
    },
    hp: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '当前生命'
    },
    mp_max: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔力上限'
    },
    mp: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '当前魔力'
    },
    atk: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '物理攻击力'
    },
    matk: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔法攻击力'
    },
    def: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '物理防御力'
    },
    mdef: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔法防御力'
    },
    hit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '命中'
    },
    dodge: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '闪避'
    },
    crit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴击'
    },
    crit_dmg: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴伤'
    },
    crit_avoid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴免'
    },
    crit_resist: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴抗'
    },
    speed: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '速度'
    },
    tenacity: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '韧性'
    },
    hp_recover: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '生命恢复'
    },
    mp_recover: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔力恢复'
    },
    // 物理精通
    stab_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '刺击精通'
    },
    slash_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '斩击精通'
    },
    strike_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '打击精通'
    },
    // 物理抗性
    stab_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '刺击抗性'
    },
    slash_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '斩击抗性'
    },
    strike_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '打击抗性'
    },
    // 元素精通
    metal_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '金元素精通'
    },
    wood_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '木元素精通'
    },
    water_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '水元素精通'
    },
    fire_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '火元素精通'
    },
    earth_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '土元素精通'
    },
    ice_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '冰元素精通'
    },
    thunder_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '雷元素精通'
    },
    wind_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '风元素精通'
    },
    light_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '光元素精通'
    },
    dark_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '暗元素精通'
    },
    // 元素抗性
    metal_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '金元素抗性'
    },
    wood_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '木元素抗性'
    },
    water_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '水元素抗性'
    },
    fire_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '火元素抗性'
    },
    earth_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '土元素抗性'
    },
    ice_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '冰元素抗性'
    },
    thunder_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '雷元素抗性'
    },
    wind_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '风元素抗性'
    },
    light_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '光元素抗性'
    },
    dark_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '暗元素抗性'
    }
  },
  {
    sequelize,
    tableName: 'user_attribute',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      },
      {
        unique: true,
        fields: ['uid']
      }
    ]
  }
)

export { user_attribute }
